<template>
  <div class="user-layout">
    <!-- 顶部栏 -->
    <header class="header">
      <div class="left">
        <button class="back-btn" @click="goBack">
          <i class="fa-solid fa-arrow-left"></i> 返回
        </button>
      </div>
      <div class="center">
        <h2>个人中心</h2>
      </div>
      <div class="right"></div>
    </header>

    <!-- 主体内容 -->
    <div class="main">
      <!-- 左侧导航栏 -->
      <aside class="sidebar">
        <div class="sidebar-header">
          <div class="user-avatar">
            <i class="fa-solid fa-user-astronaut"></i>
          </div>
          <h3>用户空间</h3>
        </div>
        <ul>
          <li
            v-for="item in menu"
            :key="item.path"
            :class="{ active: route.path === item.path }"
            @click="goTo(item.path)"
          >
            <div class="menu-icon">
              <i :class="item.icon"></i>
            </div>
            <span>{{ item.label }}</span>
            <div class="active-indicator"></div>
          </li>
        </ul>
      </aside>

      <!-- 右侧展示区 -->
      <section class="content">
        <div class="content-background">
          <div class="floating-shape shape-1"></div>
          <div class="floating-shape shape-2"></div>
          <div class="floating-shape shape-3"></div>
        </div>
        <router-view></router-view>
      </section>
    </div>
  </div>
</template>

<script setup name="UserLayout">
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

// 左侧导航菜单
// 左侧导航菜单
const menu = [
  { label: '个人资料', path: '/user/profile', icon: 'fa-solid fa-user' },
  { label: '个人收藏', path: '/user/favorites', icon: 'fa-solid fa-star' },
  { label: '个人喜好', path: '/user/likes', icon: 'fa-solid fa-heart' }, // 建议将图片图标改为心形
  { label: '我的文章', path: '/user/articles', icon: 'fa-solid fa-file-lines' }, // 修改标签和图标
  { label: '设置', path: '/user/settings', icon: 'fa-solid fa-gear' }
]

// 跳转
function goTo(path) {
  router.push(path)
}

// 返回主页
function goBack() {
  router.push('/')
}
</script>

<style scoped>
@import url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css');

/* 整体布局 */
.user-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

/* 顶部栏 */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  color: white;
  padding: 16px 30px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 10;
}

.header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg,
  rgba(102, 126, 234, 0.8) 0%,
  rgba(118, 75, 162, 0.8) 50%,
  rgba(102, 126, 234, 0.8) 100%);
  z-index: -1;
}

.header h2 {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #fff, #e3f2fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.back-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 25px;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* 主体部分 */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* 左侧导航栏 */
.sidebar {
  width: 280px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  border-right: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 5;
  transition: all 0.3s ease;
}

.sidebar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg,
  rgba(102, 126, 234, 0.3) 0%,
  rgba(118, 75, 162, 0.2) 100%);
  z-index: -1;
}

.sidebar-header {
  padding: 30px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.user-avatar {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 15px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.user-avatar i {
  font-size: 32px;
  color: white;
}

.sidebar-header h3 {
  color: white;
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 20px 0;
}

.sidebar li {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 16px 25px;
  cursor: pointer;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.sidebar li::before {
  content: '';
  position: absolute;
  left: -100%;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
  rgba(255, 255, 255, 0) 0%,
  rgba(255, 255, 255, 0.2) 50%,
  rgba(255, 255, 255, 0) 100%);
  transition: left 0.5s ease;
}

.sidebar li:hover::before {
  left: 100%;
}

.sidebar li:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
  transform: translateX(5px);
}

.sidebar li.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-left: 4px solid #4fc3f7;
}

.menu-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.sidebar li.active .menu-icon {
  background: #4fc3f7;
  transform: scale(1.1);
}

.active-indicator {
  width: 6px;
  height: 6px;
  background: #4fc3f7;
  border-radius: 50%;
  margin-left: auto;
  opacity: 0;
  transition: all 0.3s ease;
}

.sidebar li.active .active-indicator {
  opacity: 1;
  transform: scale(1.2);
}

/* 内容展示区 */
.content {
  flex: 1;
  position: relative;
  padding: 30px 40px;
  overflow-y: auto;
}

.content-background {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  pointer-events: none;
}

.floating-shape {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle,
  rgba(79, 195, 247, 0.1) 0%,
  rgba(102, 126, 234, 0.05) 70%);
  animation: float 6s ease-in-out infinite;
}

.shape-1 {
  width: 200px;
  height: 200px;
  top: 10%;
  right: 10%;
  animation-delay: 0s;
}

.shape-2 {
  width: 150px;
  height: 150px;
  bottom: 20%;
  left: 5%;
  animation-delay: 2s;
}

.shape-3 {
  width: 100px;
  height: 100px;
  top: 50%;
  right: 20%;
  animation-delay: 4s;
}

@keyframes float {
  0%, 100% {
    transform: translateY(0px) rotate(0deg);
  }
  50% {
    transform: translateY(-20px) rotate(180deg);
  }
}

/* 滚动条美化 */
.content::-webkit-scrollbar {
  width: 8px;
}

.content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.content::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea, #764ba2);
  border-radius: 4px;
}

.content::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #5a6fd8, #6a4190);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .sidebar {
    width: 70px;
  }

  .sidebar-header h3,
  .sidebar li span {
    display: none;
  }

  .sidebar-header {
    padding: 20px 10px;
  }

  .user-avatar {
    width: 50px;
    height: 50px;
  }

  .user-avatar i {
    font-size: 20px;
  }

  .content {
    padding: 20px;
  }

  .header {
    padding: 12px 20px;
  }

  .header h2 {
    font-size: 20px;
  }
}

/* 添加一些微妙的动画 */
.sidebar {
  animation: slideInLeft 0.5s ease-out;
}

.content {
  animation: slideInRight 0.5s ease-out;
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
</style>
